//
//  WQComposePictureView.swift
//  WeiBo
//
//  Created by 张德华 on 7/26/16.
//  Copyright © 2016 ZhangDeHua. All rights reserved.
//

import UIKit

class WQComposePictureView: UICollectionView {
    
    /**闭包通知控制器弹出相册*/
    var closure: (() -> ())?
    
    
    
    
    
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    private func setupUI() {
        
        backgroundColor = RandomColor()
        dataSource = self
        
        let margin: CGFloat = 5
        let cellWH = (SCREENSIZE.width - 20 - margin*2) / 3
        
        let layout = self.collectionViewLayout as? UICollectionViewFlowLayout
        layout?.itemSize = CGSize(width: cellWH, height: cellWH)
        layout?.minimumLineSpacing = margin
        layout?.minimumInteritemSpacing = margin
        
        
        registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell")
        
        
    }
    
    
    // MARK: - ************数据源代理

}


extension WQComposePictureView: UICollectionViewDataSource {
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 9
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath)
        
        cell.backgroundColor = RandomColor()
        return cell
    }
    
    
}
